package com.xly.webclick;

import android.app.Instrumentation;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.webkit.JavascriptInterface;

/**
 * Created by xuleyuan on 2018/8/15
 */

public class JSUseAndroid {

    public JSUseAndroid() {
    }

    public void Click3(double paramDouble1, double paramDouble2) {
        Instrumentation localInstrumentation = new Instrumentation();
        localInstrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), 0, (float) paramDouble1, (float) paramDouble2, 0));
        localInstrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), 1, (float) paramDouble1, (float) paramDouble2, 0));
    }

    public void DoubleTap(double paramDouble1, double paramDouble2) {
        if ((paramDouble1 <= 0.0D) || (paramDouble2 <= 0.0D)) {
            return;
        }
        String str = "input tap " + paramDouble1 + " " + paramDouble2;
        try {
            Runtime.getRuntime().exec(str);
            Runtime.getRuntime().exec(str);
            return;
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }

    public void SwipTouch(double paramDouble1, double paramDouble2) {
        if ((paramDouble1 <= 0.0D) || (paramDouble2 <= 0.0D)) {
            return;
        }
        String str = "input swipe " + paramDouble1 + " " + paramDouble2 + " " + paramDouble1 + " " + paramDouble2;
        try {
            Runtime.getRuntime().exec(str);
            return;
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }

    @JavascriptInterface
    public void pressEnter() {
        new Thread(new Runnable() {
            public void run() {
                new Instrumentation().sendCharacterSync(66);
            }
        }).start();
    }

    @JavascriptInterface
    public void tap(double paramDouble1, double paramDouble2) {
        if ((paramDouble1 <= 0.0D) || (paramDouble2 <= 0.0D)) {
            return;
        }
        String str = "input tap " + paramDouble1 + " " + paramDouble2;
        try {
            Runtime.getRuntime().exec(str);
            return;
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }

}
